package kuzmenkov.applet;

import java.awt.Checkbox;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

/**
 * The class is responsible for listening a layout choosing
 * @author Michael Kuzmenkov
 *
 */
public class ChoosingLayoutActionListener implements ItemListener{
	
	private ViewerApplet viewerApplet;
	
	public ChoosingLayoutActionListener(ViewerApplet viewerApplet) {
		if (viewerApplet== null)
			throw new IllegalArgumentException("The argument viewerApplet is null");
		this.viewerApplet = viewerApplet;
	}

	@Override
	public void itemStateChanged(ItemEvent e) {
		if (e.getStateChange()==ItemEvent.DESELECTED)			
			return;
		
		
		Object source = e.getSource();
		Checkbox box = null;
		if (source instanceof Checkbox){
			box = (Checkbox) source;
		} else 
			assert (false);
		
		String command = box.getLabel();
		
		assert (command!=null && !command.isEmpty());
		
		if (command.equals(ViewerApplet.ICON_VIEW_BUTTON)){
			viewerApplet.applyIconView();
		} else if (command.equals(ViewerApplet.CIRCLE_VIEW_BUTTON)){
			viewerApplet.applyClockLayout();
		} else 
			assert (false): "An unexpected event";
		
	}	
	

}
